package com.gxa.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.entity.CustomerManagement;
import com.gxa.mapper.CustomerManagementMapper;
import com.gxa.service.CustomerManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerManagementServiceImpl implements CustomerManagementService {

    @Autowired
    CustomerManagementMapper customerManagementMapper;

    int i =-1;
    /**
     * 查询所有客服信息
     * @param currentPage 当前页
     *      * @param pageSize 每一页显示条数
     *      * @return 客服列表
     */
    @Override
    public PageInfo<CustomerManagement> getCustomerManagementList(Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<CustomerManagement> customerManagementList = customerManagementMapper.selectCustomerManagementList();
        PageInfo<CustomerManagement> pageInfo = new PageInfo(customerManagementList);
        System.out.println(pageInfo.getTotal());

        return pageInfo;
    }

    /**
     * 添加客服信息
     * @param customerManagement 客服对象
     * @return 添加成功或失败
     */
    @Override
    public boolean addCustomerManagement(CustomerManagement customerManagement) {

        int i = customerManagementMapper.insertCustomerManagement(customerManagement);

        return i>0?true:false;
    }

    /**
     * 更新客服信息
     * @param customerManagement 客服对象
     * @return 是否成功
     */
    @Override
    public boolean updateCustomerManagement(CustomerManagement customerManagement) {
        int i = customerManagementMapper.updateCustomerManagement(customerManagement);

        return i>=0?true:false;
    }

    /**
     * 获取到客服信息
     *
     * @param id 客服id
     * @return 客服对象
     */
    @Override
    public CustomerManagement getCustomerManagementById(Integer id) {
        CustomerManagement  selectCustomerManagementById= customerManagementMapper.selectCustomerManagementById(id);

        return selectCustomerManagementById;
    }

    /**
     * 删除客服信息
     * @param id 客服id
     * @return 删除是否成功
     */
    @Override
    public boolean delCustomerManagement(Integer id) {

        int i = customerManagementMapper.deleteCustomerManagement(id);

        return i>=0?true:false;
    }

    /**
     * 根据标题查询客服信息
     * @param title 客服标题
     * @return 客服列表
     */
    @Override
    public PageInfo<CustomerManagement> getCustomerManagementListByTitle(String title) {

        List<CustomerManagement> getByTitle = customerManagementMapper.selectCustomerManagementByTitle(title);
        PageInfo<CustomerManagement> pageInfo = new PageInfo<>(getByTitle);

        return pageInfo;
    }


}
